import 'package:example/app/routes/app_pages.dart';
import 'package:example/app/theme/app_text_theme.dart';
import 'package:flutter_base_framework/flutter_base_framework.dart';
import 'login_controller.dart';
import 'package:flutter/material.dart';

import 'widget/edit_text_view.dart';

class LoginPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetBuilder<LoginController>(
      builder: (logic) {
        return Scaffold(
          appBar: AppBar(
            title: Text(
              '登录',
              style: appBarTextStyle,
            ),
            leading: IconButton(
              icon: Icon(Icons.arrow_back_ios),
              onPressed: () => Get.back(),
            ),
          ),
          body: Container(
            width: Get.infinity,
            height: Get.infinity,
            child: Column(
              children: [
                Get.heightBox(60.dp),

                /// 用户名
                EditTextView(
                  controller: logic.userNameController,
                  widget: Get.screenWidth * 0.8,
                  height: 50.dp,
                  borderRadius: 50.dp,
                  backgroundColor: '#eeeeee'.c,
                  hintText: '请输入用户名',
                  hintStyle: appLoginModulesHintTextStyle,
                  textStyle: appLoginModulesContentTextStyle,
                  keyboardType: TextInputType.text,
                  leftIcon: Icon(
                    Icons.account_box_outlined,
                    color: Colors.blueAccent,
                    size: 24.dp,
                  ),
                  rightIcon: Icon(
                    Icons.close,
                    color: Colors.grey,
                    size: 24.dp,
                  ),
                  rightClick: () {
                    logic.userNameController.clear();
                  },
                ),
                Get.heightBox(30.dp),

                /// 密码
                EditTextView(
                  controller: logic.passwordController,
                  widget: Get.screenWidth * 0.8,
                  height: 50.dp,
                  borderRadius: 50.dp,
                  backgroundColor: '#eeeeee'.c,
                  hintText: '请输入密码',
                  hintStyle: appLoginModulesHintTextStyle,
                  textStyle: appLoginModulesContentTextStyle,
                  keyboardType: TextInputType.text,
                  obscureText: true,
                  maxLines: 1,
                  leftIcon: Icon(
                    Icons.lock_outline,
                    color: Colors.blueAccent,
                    size: 24.dp,
                  ),
                  rightIcon: Icon(
                    Icons.close,
                    color: Colors.grey,
                    size: 24.dp,
                  ),
                  rightClick: () {
                    logic.passwordController.clear();
                  },
                ),
                Get.heightBox(30.dp),

                /// 登录按钮
                TextButton(
                    onPressed: () => logic.login(),
                    style: TextButton.styleFrom(
                      backgroundColor: Colors.blueAccent,
                      minimumSize: Size(Get.width * 0.6, 44.dp),
                    ),
                    child: Text(
                      '登录',
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 16.sp,
                      ),
                    )),
                Get.heightBox(30.dp),

                /// 注册入口
                InkWell(
                  onTap: () => Get.toNamed(Routes.REGISTER),
                  child: Text(
                    '去注册 ->',
                    style: TextStyle(
                      color: Colors.blueAccent,
                      fontSize: 16.sp,
                      decoration: TextDecoration.underline,
                    ),
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );
  }
}
